﻿using NServiceBus.Management.Messages.Status;
using NUnit.Framework;
using Rhino.Mocks;

namespace NServiceBus.Management.UnitTests.Managers
{
    [TestFixture]
    public class The_endpoint_manager_should
    {
        [Test]
        public void Send_onlinemessage_on_startup()
        {
            var bus = MockRepository.GenerateStub<IBus>();
            
            new EndpointManager()
                {
                    Bus = bus
                }
                .Start();

            bus.AssertWasCalled(x => x.Send(
                    Arg<IMessage[]>.Matches(
                    p => (p[0] is OnlineMessage))));
        }

        [Test]
        public void Send_offlinemessage_on_shutdown()
        {
            var bus = MockRepository.GenerateStub<IBus>();

            new EndpointManager()
                {
                    Bus = bus
                }.Stop();

            bus.AssertWasCalled(x => x.Send(
                    Arg<IMessage[]>.Matches(
                    p => (p[0] is OfflineMessage))));
        }
    }
}
